package c.j.a.d.b.i;

import android.net.TrafficStats;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import c.j.a.d.b.i.k.b;
import java.util.concurrent.atomic.AtomicInteger;

/* compiled from: DeviceBandwidthSampler */
public class c {
    public static final String e = "c";
    public static long f = -1;
    public static volatile c g;
    public final k a = b.a;
    public final AtomicInteger b = new AtomicInteger();
    public final a c;
    public long d;

    /* compiled from: DeviceBandwidthSampler */
    public class a extends Handler {
        public a(Looper looper) {
            super(looper);
        }

        public void handleMessage(Message message) {
            if (message.what == 1) {
                c.this.b();
                sendEmptyMessageDelayed(1, 1000);
            }
        }
    }

    public c() {
        HandlerThread handlerThread = new HandlerThread("ParseThread");
        handlerThread.start();
        this.c = new a(handlerThread.getLooper());
    }

    public static c a() {
        if (g == null) {
            synchronized (c.class) {
                if (g == null) {
                    g = new c();
                }
            }
        }
        return g;
    }

    public void b() {
        try {
            long totalRxBytes;
            if (c.j.a.d.b.n.a.t(c.j.a.d.b.e.b.a())) {
                totalRxBytes = TrafficStats.getTotalRxBytes() - TrafficStats.getMobileRxBytes();
            } else {
                totalRxBytes = TrafficStats.getMobileRxBytes();
            }
            long j = f;
            long j2 = totalRxBytes - j;
            if (j >= 0) {
                synchronized (this) {
                    j = SystemClock.uptimeMillis();
                    this.a.a(j2, j - this.d);
                    this.d = j;
                }
            }
            f = totalRxBytes;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
